package com.prd.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Author lizhaoyi
 * @date 2023/11/20 12:54
 * Description:
 */
public class CheckUtil {

    /**
     * 手机号正则
     */
    private static final Pattern PHONE_PATTERN = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");


    /**
     * @param phone
     * @return
     */
    public static boolean isPhone(String phone) {
        if (null == phone || "".equals(phone)) {
            return false;
        }
        Matcher m = PHONE_PATTERN.matcher(phone);
        return m.matches();

    }

    /**
     * 是否有效密码
     * @param password
     * @return
     */
    public static boolean isValidPassword(String password) {
        // 密码长度为6以上，且同时包含数字和字母
        String pattern = "^(?=.*[a-zA-Z0-9]).{6,}$";
        Pattern regex = Pattern.compile(pattern);
        Matcher matcher = regex.matcher(password);
        return matcher.matches();
    }

    /**
     * 身份证是否有效
     * @param password
     * @return
     */
    public static boolean isValidIDCard(String password) {
        String pattern = "^[1-9]\\d{5}(19|20)\\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\\d{3}[Xx\\d]$";
        Pattern regex = Pattern.compile(pattern);
        Matcher matcher = regex.matcher(password);
        return matcher.matches();
    }
}
